package com.wuuxiang.polestar.demo.springboot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.wuuxiang.polestar.core.GeneralConfigGroup;
import com.wuuxiang.polestar.core.zookeeper.surpass.ZookeeperSurPassConfigGroup;
import com.wuuxiang.polestar.core.zookeeper.surpass.ZookeeperSurPassConfigProfile;

/**********************************************************
 * 类名称：PolestartConfig 	<br>
 * 类描述：   				<br>
 * 创建人：liuwei 			<br>
 * 创建时间：2018年1月5日上午10:56:52	<br>
 * 修改备注：   				<br>
 **********************************************************/
@Configuration
@EnableConfigurationProperties(PolestartInitBean.class)
public class PolestartConfig {

	@Autowired
	private PolestartInitBean polestartInitBean;
	
	@Bean(name="generalConfigGroup")
	public GeneralConfigGroup init() {
		ZookeeperSurPassConfigProfile profile = new ZookeeperSurPassConfigProfile(polestartInitBean.getAddress(), polestartInitBean.getTeamName(),Boolean.parseBoolean(polestartInitBean.getLoadDef()));
		String nodes = polestartInitBean.getNodes();
		ZookeeperSurPassConfigGroup zkConfigGroup = null;
		for (String node : nodes.split(",")) {
			if(zkConfigGroup == null) {
				zkConfigGroup = new ZookeeperSurPassConfigGroup(profile, node);
			} else {
				zkConfigGroup.putAll(new ZookeeperSurPassConfigGroup(profile, node));
			}
		}
		return zkConfigGroup;
	}
}
